package taskTracker.ui.lite;

import java.io.IOException;
import java.util.Enumeration;
import java.util.Vector;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.Image;

import taskTracker.Project;

/**
 * A form that lists some Projects and allow navigation between them
 * 
 * @author aseldawy
 * 
 */
public class ProjectListUI extends List {

	/**Command for adding a new list*/
	final Command cmdAdd = new Command("Add Project", Command.SCREEN, 2);

	/**Command to edit a list*/
	final Command cmdEdit = new Command("Edit Project", Command.SCREEN, 3);

	/**Command to issue a delete*/
	final Command cmdDelete = new Command("Delete Project", Command.SCREEN, 4);
	
	/**Image displayed as an icon for projects*/
	private static Image projectImage;
	
	static {
		try {
			projectImage = Image.createImage("/project.png");
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * Creates a new ProjectList from the given list of Projects
	 * @param projects
	 */
	public ProjectListUI(Vector projects) {
		super("Projects", List.IMPLICIT);

		for (Enumeration e = projects.elements();e.hasMoreElements();) {
			Project project = (Project) e.nextElement();
			super.append(project, projectImage);
		}

		super.addCommand(cmdAdd);
		if (this.size() > 0) {
			super.addCommand(cmdEdit);
			super.addCommand(cmdDelete);
		}
	}

}
